package com.example.module_hp_white_noise;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.lifecycle.Observer;

import com.alibaba.android.arouter.facade.annotation.Route;

import com.example.module_hp_white_noise.activity.HpSleepBreatheActivity;
import com.example.module_hp_white_noise.activity.HpSleepFocusActivity;
import com.example.module_hp_white_noise.activity.HpSleepMonitorActivity;
import com.example.module_hp_white_noise.activity.HpSleepPlayActivity;
import com.example.module_hp_white_noise.base.BaseMvvmFragment;
import com.example.module_hp_white_noise.base.BaseViewModel;
import com.example.module_hp_white_noise.databinding.FragmentHpSleepMainBinding;
import com.fwlst.lib_base.utils.AdUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

@Route(path = "/hpWhiteNoise/route/HpSleepMainActivity")
public class HpSleepMainFragment extends BaseMvvmFragment<FragmentHpSleepMainBinding, BaseViewModel> {
    @Override
    protected int initLayout() {
        return R.layout.fragment_hp_sleep_main;
    }

    @Override
    protected int initBR() {
        return BR.data;
    }

    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        getMoment();
        //banner广告
        AdUtils.INSTANCE.loadBannerAd(mContext,binding.bannerContainer);
        //监听点击事件
        viewModel.getCurrentType().observe(this, new Observer<Integer>() {
            @Override
            public void onChanged(Integer integer) {
                if(integer==0) return;
                switch (integer){
                    case 1://跳转到专注
                        navigateTo(HpSleepFocusActivity.class);
                        break;
                    case 2://跳转到有氧呼吸
                        navigateTo(HpSleepBreatheActivity.class);
                        break;
                    case 3://跳转到沉浸时刻
                        navigateTo(HpSleepPlayActivity.class);
                        break;
                    case 4://跳转到噪音监测
                        navigateTo(HpSleepMonitorActivity.class);
                        break;
                }
            }
        });
    }
    //根据时间判断
    private void getMoment() {
        Date date = new Date();
        SimpleDateFormat df = new SimpleDateFormat("HH");
        String str = df.format(date);
        int a = Integer.parseInt(str);
        String moment = "";
        if (a >= 0 && a <= 6) {
            moment = "凌晨时刻";
        }
        if (a > 6 && a <= 12) {
            moment = "上午好";
        }
        if (a > 12 && a <= 13) {
            moment = "中午好";
        }
        if (a > 13 && a <= 18) {
            moment = "下午好";
        }
        if (a > 18 && a <= 24) {
            moment = "晚上好";
        }
        binding.sleepMoment.setText(moment);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        AdUtils.INSTANCE.destroyBannerAd();
    }
}
